/*
 * @version May 28, 2011
 * Thach changed the types of various collections from List to Set to reflect
 * new parameters.
 */

package parsers;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import user.User;
import user.UserType;
import data.ClassPreference;
import data.TimeSlot;

public class UserParserTest {
	private UserParser userParser;
	private TimeSlotParser timeSlotParser;
	private ClassParser classParser;
	
	@Before
	public void setUp() throws IOException {
		
		classParser = new ClassParser(new File("classes.txt"));
		Set<ClassPreference> classes = classParser.getClasses(); // List of Classes parsed from file
		timeSlotParser = new TimeSlotParser(new File("TimeSlots.txt"));
		Set<TimeSlot> ts = new HashSet<TimeSlot>(timeSlotParser.getTimeSet()); // List of TimeSlots parsed from file.
		userParser = new UserParser(new File("users.txt"), classes, ts);
	}
	
	@Test
	public void test1() {
		List<User> users = userParser.getUserList();
		StringBuilder sb = new StringBuilder();
		for (User user: users) {
			sb.append(user.getUserID());
			sb.append(",");
			sb.append(user.getName());
			sb.append(",");
			for (UserType type: user.getUserType()) {
				switch(type) {
				case ADVISER:
					sb.append(type.toString());
					sb.append(",");
					sb.append(user.getClasses(type));
					break;
				case SCHEDULER:
					sb.append(type.toString());
					break;
				case STUDENT:
					sb.append(type.toString());
					sb.append(",");
					sb.append(user.getTimes(type));
					sb.append(user.getClasses(type));
					break;
				case TEACHER:
					sb.append(type.toString());
					sb.append(",");
					sb.append(user.getTimes(type).toString());
					sb.append(user.getClasses(type));
					break;
				}
				sb.append("\n");
			}
		}
		System.out.println(sb);
	}
}
